<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="../css/public.css">
</head>

<body>
    <!-- textBaseline  设置或返回在绘制文本时的当前文本基线 -->

    <canvas id="myCanvas" width="300" height="150" style="border:1px solid #d3d3d3;"></canvas>

    <script>
        var c = document.getElementById("myCanvas");
        var ctx = c.getContext("2d");

        //在位置 y=100 绘制蓝色线条
        ctx.strokeStyle = "blue";
        ctx.moveTo(5, 100);
        ctx.lineTo(395, 100);
        ctx.stroke();
        ctx.font = "20px Arial"

        //在 y=200 以不同的 textBaseline 值放置每个单词
        ctx.textBaseline = "top";
        ctx.fillText("Top", 5, 100);
        ctx.textBaseline = "bottom";
        ctx.fillText("Bottom", 50, 100);
        ctx.textBaseline = "middle";
        ctx.fillText("Middle", 120, 100);
        ctx.textBaseline = "alphabetic";
        ctx.fillText("Alphabetic", 190, 100);
        ctx.textBaseline = "hanging";
        ctx.fillText("Hanging", 290, 100);
    </script>
</body>

</html>